package com.visionblue.business.ship.model.enums

import java.math.BigDecimal
import java.math.RoundingMode

/**
 * @author: xlh
 * @date: 2020-05-21 3:50 PM
 * @desc:  污染物类型
 */
enum class WasteTypeEnum(val code: String, val desc: String) {


    OIL_WASTE("C110011", "含油污水"),
    LIFE_WASTE("C110012", "生活污水"),
    RESIDUAL_OIL("C110013", "废机油"),
    SOLID_WASTE("C110015", "生活垃圾"),
   /* OIL_WASTE("1", "含油污水"),
    LIFE_WASTE("2", "生活污水"),
    SOLID_WASTE("3", "生活垃圾"),
    OIL_PACKAGE("4", "油包"),
    WASTE_LEAD_ACID_BATTERY("5", "废铅酸电池"),
    HAZARDOUS_WASTE("6", "含有毒液体物质的污水"),
    RESIDUAL_OIL("7", "残油"),*/


    OIL_UNDEFINE("-1", ""),
    WATER_UNDEFINE("-2", ""),
    ULTRA_UNDEFINE("-3", ""),
    WASTE_WATER_UNDEFINE("-4", ""),
//    FLOW_UNDEFINE("-1", "")
    ;


    fun isSolid(): Boolean {
        return this == SOLID_WASTE
    }

/*    fun isSolid(): Boolean {
        return this == SOLID_WASTE || this == OIL_PACKAGE || this == WASTE_LEAD_ACID_BATTERY
    }

    fun isOil(): Boolean {
        return this == RESIDUAL_OIL || this == OIL_WASTE
    }

    fun isWater(): Boolean {
        return this == LIFE_WASTE || this == HAZARDOUS_WASTE
    }*/



    fun isOil(): Boolean {
        return this == RESIDUAL_OIL || this == OIL_WASTE
    }

    fun isWater(): Boolean {
        return this == LIFE_WASTE
    }

    companion object {

        fun getWasteType(code: String?): WasteTypeEnum? {
            return values().find { it.code == code }
        }
    }
}

fun WasteTypeEnum?.getUnitText(value: String): String {
    return when {
/*        this?.isSolid() == true -> {
            "T"
        }*/
        this == WasteTypeEnum.RESIDUAL_OIL -> {
            // 密度 0.9
            val weight =
                BigDecimal(value)
                    .multiply(BigDecimal(OIL_DENSITY))
                    .setScale(3, RoundingMode.HALF_DOWN)
                    .toPlainString()
            "m^3(约$weight T)"
//            "m^3"
        }
        this == WasteTypeEnum.SOLID_WASTE -> {
            "KG"
//            "m^3"
        }
        else -> {
            "m^3(约${BigDecimal(value).setScale(3, RoundingMode.HALF_DOWN)
                .toPlainString()} T)"
//            "m^3"
        }
    }
}

const val OIL_DENSITY = 0.89